package com.gtw.modules.sys.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.gtw.common.utils.Query;
import com.gtw.common.utils.R;
import com.gtw.modules.sys.service.SysCommodityPropertyService;
import com.gtw.modules.entity.TbCommodityProperty;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 商品与属性中间表
 *
 * @author wuye
 * @email www.baidu.com
 * @date 2018-02-01 10:46:46
 */
@RestController
@RequestMapping("/sys/commodityproperty")
public class SysCommodityPropertyController {
    @Autowired
    private SysCommodityPropertyService commodityPropertyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:commodityproperty:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        Page<TbCommodityProperty> pageUtil = new Page<TbCommodityProperty>(query.getPage(), query.getLimit());
        Page<TbCommodityProperty> page = commodityPropertyService.queryPageList(pageUtil, query);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        TbCommodityProperty commodityProperty = commodityPropertyService.queryObject(id);

        return R.ok().put("commodityProperty", commodityProperty);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:commodityproperty:save")
    public R save(@RequestBody TbCommodityProperty commodityProperty) {
        commodityPropertyService.save(commodityProperty);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:commodityproperty:update")
    public R update(@RequestBody TbCommodityProperty commodityProperty) {
        commodityPropertyService.update(commodityProperty);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:commodityproperty:delete")
    public R delete(@RequestBody Integer[] ids) {
        commodityPropertyService.deleteBatch(ids);

        return R.ok();
    }

}
